<?php
//
// +------------------------------------------------------------------------+
// | PHP Version 5.4                                                        |
// +------------------------------------------------------------------------+
// | Copyright (c) All rights reserved.                                     |
// +------------------------------------------------------------------------+
// | 世纪车来车往(北京）网络科技有限公司 版权所有！                         |
// | TEL:010-63732365  HOTLINE:400-6688-365  EMAIL:clcw@clcw.com.cn         |
// | $Revision: 1.0 $                                                       |
// +------------------------------------------------------------------------+
// | Author: songaimin@clcw.com.cn  Blog:http://blog.csdn.net/samxx8        |
// +------------------------------------------------------------------------+
//
namespace AuctionCore\Account;
use  AuctionCore\System\AuctionException;
use \AuctionCore\Common\PhpMemcache;



/**
* 车主前台帐号
* @author  爱民
*/
class OwnerUser extends \AuctionCore\Account\FrontUser {


	//不传密码，登录方式
    public static function loginByLoginKey($user_name,$login_key,$time){

        //只限经纪人和车主可以登录
        $ou = new \AuctionCore\Account\OwnerUser($user_name);        
        if (!$ou->check_auth("owner_center")) {
            AuctionException::make_throw('400003');
        }
        
        return  parent::loginByLoginKey($user_name,$login_key,$time);
        
    }

    /**
    * 创建车主用户
    * @param array $info [user_name=用户名，passwd=密码,nick_name=昵称,pwd_mobile=密保手机号,smspwd_mobile=短信手机号,in_code=邀请码]
    * @return int $user_id
    */
    public static function create($info,$is_md5=false){
        $in_code = $info['in_code'];
        unset($info['in_code']);

        $user_id = parent::create($info,$is_md5);

        if($user_id){
            //经纪人信息
            $in_aid = '';
            if($in_code){
                $broker = array();
                $in_des = \AuctionCore\Broker\Broker::get_detail_by_params(array('invite_code'=>$in_code));
                if($in_des)
                    $in_aid = $in_des['aid'];    
            }
            $aid = \AuctionCore\Broker\Broker::create($user_id,$in_aid);

            if($in_code){ // 被邀请注册的 发红包
                //添加记录
                $amount = C('RED_PACKETS_AMOUNT.invite_amount');
                $rate = C('RED_PACKETS_AMOUNT.divide_rate');
                $rp_id = \AuctionCore\Broker\RedPackets::add($in_aid,$aid,1,$amount);
                \AuctionCore\Broker\Commission::addLog($rp_id,$aid,$in_aid,4,$amount*$rate);
                \AuctionCore\Broker\Commission::addLog($rp_id,$in_aid,$aid,1,$amount*(1-$rate));
                //设置团队
                \AuctionCore\Broker\Broker::set_team($in_aid);
            }
            //设置用户车主表组
            $au = new \AuctionCore\Account\AgentUser($user_id);
            $au->set_group_by_title('owner_group');
        }
        return $user_id;

    }
}
